version 14.1
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.V OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

*-----------------------------------
* 	WITHOUT CONTROLS
*-----------------------------------

/* DEFINING TIME VARIABLE */		

use				"$project_data\ExemptionCutoff_06_11.dta",clear
sort			regnor year
local 			var="seinc"
local			lbound=80000
local			ubound=500000
keep			if employee==0

/* LOG CHANGE IN EARNINGS */

keep 			`var' regnor year industry2 taxableinc location_code tax_office_id
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011

/* GENERATING TREATMENT DUMMIES */

g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011
qui				tab year, g(ydum)

/* COLUMN (1) */

local			i=1
local			j=1
qui				reg logchange ydum2 ydum3 m_09 m_10 t_09 post, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (2) -- LINEAR */

local			i=1
qui				reg logchange trend m_09 m_10 t_09 post, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (3) */

local			i=1
qui				reg logchange i.location_code ydum2 ydum3 m_09 m_10 t_09 post if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & location_code>=0
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (4) */

local			i=1
qui				reg logchange i.tax_office_id ydum2 ydum3 m_09 m_10 t_09 post, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & tax_office_id!=. 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (5) */

local			i=1
qui				reg logchange i.industry ydum2 ydum3 m_09 m_10 t_09 post, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=. 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (6) */

local			i=1
qui				reg logchange i.location_code i.tax_office_id i.industry ydum2 ydum3 m_09 m_10 t_09 post if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=. & location_code>=0 & tax_office_id!=. 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (7) -- INDUSTRY-SPECIFIC */

local			i=1
qui				xi: reg logchange i.year*i.industry2  m_09 m_10 t_09 post, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (8) -- INDUSTRY-SPECIFIC */

local			i=1
qui				xi: reg logchange i.year*i.industry2 i.location_code i.tax_office_id  m_09 m_10 t_09 post if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[post]
matrix			table[`i'+1,`j']=_se[post]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=. & location_code>=0 & tax_office_id!=.
matrix			table[`i',`j']=r(mean)

/* FORMATTING TABLE */  

svmat 			table
keep			tab*
drop			table9
keep			if _n<=10
g				c11=""
replace			c11="$\mbox{\emph{to-zero}} \times 2009$" in 1
replace			c11="$\mbox{\emph{to-zero}} \times 2010$" in 3
replace			c11="$\mbox{\emph{not-to-zero}} \times 2009$" in 5
replace			c11="post$" in 7
replace			c11="Observations" in 9
forvalues 		c=1/8 {
g				c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)8 {
forvalues		c=1/8 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/8 {
replace			c`c'=string(table`c',"%15.0fc") in 9
}
forvalues		s=1/8 {
g				s`s'="&"
}
g				l="\\"
replace			l="\\\\" in 8
browse			c11 s8 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 s7 c8 l
